package vno.sci.window
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	import org.aswing.AsWingManager;
	import org.aswing.AssetBackground;
	import org.aswing.BoxLayout;
	import org.aswing.EmptyLayout;
	import org.aswing.JButton;
	import org.aswing.JFrame;
	import org.aswing.JLabel;
	import org.aswing.JPanel;
	import org.aswing.JPopup;
	import org.aswing.JScrollPane;
	import org.aswing.JTextArea;
	import org.aswing.JWindow;
	import org.aswing.event.FrameEvent;
	import org.aswing.event.ResizedEvent;
	
	import vno.fux.res.pool.BitmapAttacher;
	import vno.sci.event.MonologEvent;
	import vno.sci.window.Monolog;
	import vno.sci.window.MyButton;
	import vno.sci.window.MonologController;
	import vno.sci.window.MonologModel;
	
	public class MonologView
	{
		private var model:MonologModel;
		private var controller:MonologController;
		//		private var parentP:DisplayObjectContainer;
		
		private var frame:OFrame;
		
		public function MonologView(aModel:MonologModel, oController:MonologController, parent_:DisplayObjectContainer, frameBG:BitmapAttacher, textBG:BitmapAttacher)
		{
			//		AsWingManager.initAsStandard(parent_);
			frame = new OFrame(parent_,false,frameBG,textBG);
			
			// add reference
			model = aModel;
			controller = oController;
			
			// add Model listener
			model.addEventListener(Event.CHANGE, this.update);
			
			// send input to Controller
			frame.addEventListener(MouseEvent.CLICK,controller.handle);
			frame.prevBtn.addEventListener(MouseEvent.CLICK,controller.handlePrev);
			frame.nextBtn.addEventListener(MouseEvent.CLICK,controller.handleNext);
			
			
			//newly added 20130511.215154
			frame.xbtn.addEventListener(MouseEvent.CLICK,controller.handleSomeButton);
			
			// add to Parent as a child
			
			frame.show();
		}
		/**
		 * This is private. 
		 * @return 
		 * 
		 */
		public function getDisplayObject():DisplayObject
		{
			return frame;
		}
		public function update(event:Event):void
		{
			if (model.visible)
			{
				frame.buttonHeight = model.buttonHeight;
				frame.titleHeight = model.titleHeight;
				
				frame.setSizeWH(model.width, model.height);
				frame.setTitle(model.title);
				if (model.htmlText != "")
				{
					frame.text.setHtmlText(model.htmlText);
				}
				else
				{
					frame.text.setText(model.text);
				}
				
				// begin layout
				//buttonBar
				//frame.buttonBar.setSizeWH(model.windowWidthP*3/4,frame.buttonHeight);
				frame.buttonBar.setLocationXY((model.windowWidthP-frame.buttonBar.width)/2,model.windowHeightP-frame.buttonHeight);
				
				//textPane
				frame.textPane.setSizeWH(model.windowWidthP*model.textRange, model.windowHeightP-frame.buttonHeight-frame.titleHeight);
				frame.textPane.setLocationXY((model.windowWidthP-frame.textPane.width)/2,frame.titleHeight);
				
				//auto
				frame.text.setSizeWH(model.windowWidthP*model.textRange, model.windowHeightP-frame.buttonHeight-frame.titleHeight);
				//raw
				//frame.text.setSizeWH(model.textWidthP, model.textHeightP);
				
				//title
				frame.myTitle.setSizeWH(model.windowWidthP, frame.titleHeight);
				frame.myTitle.setLocationXY(0,0);
				
				
				//newly added.20130511.222056
				frame.controlButtonPane.setLocationXY(model.windowWidthP-25*frame.controlButtonPane.numChildren, 0);
				
				//			this.x = model.x;
				//			this.y = model.y;
				
				frame.x = model.x;
				frame.y = model.y;
				
				// end layout
				
				frame.visible = true;
			}
			else
			{
				frame.visible = false;
			}
		}
	}
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.net.URLRequest;

import org.aswing.AsWingManager;
import org.aswing.AssetBackground;
import org.aswing.BoxLayout;
import org.aswing.EmptyLayout;
import org.aswing.JButton;
import org.aswing.JFrame;
import org.aswing.JLabel;
import org.aswing.JPanel;
import org.aswing.JPopup;
import org.aswing.JScrollPane;
import org.aswing.JTextArea;
import org.aswing.JWindow;
import org.aswing.event.FrameEvent;
import org.aswing.event.ResizedEvent;

import vno.fux.res.pool.BitmapAttacher;
import vno.sci.event.MonologEvent;
import vno.sci.window.Monolog;
import vno.sci.window.MyButton;

class OFrame extends JPopup
{
	public var buttonHeight:int = 30;
	public var titleHeight:int = 50;
	
	public var myTitle:JLabel = new JLabel("Title");
	public var text:JTextArea = new JTextArea();
	public var textPane:JScrollPane = new JScrollPane(text);
	
	//	public var prevBtn:JButton = new JButton("Previous");
	private var skin:Bitmap = new Bitmap(new BitmapData(100,100,false,0x13579b));
	private var skin2:Bitmap = new Bitmap(new BitmapData(100,100,false,0x79acae));
	private var skin3:Bitmap = new Bitmap(new BitmapData(100,100,false,0xace000));
	public var prevBtn:MyButton = new MyButton("PrevBtn", null, "Prev",skin,skin2,skin3);
	public var nextBtn:JButton = new JButton("Next");
	public var buttonLayout:BoxLayout = new BoxLayout(BoxLayout.X_AXIS,10);
	public var buttonBar:JPanel = new JPanel(buttonLayout);
	
	public var windowWidth:int = 300;
	public var windowHeight:int = 200;
	
	
	
	
	
	public var _btn:JButton = new JButton("_");
	public var obtn:JButton = new JButton("o");
	public var xbtn:JButton = new JButton("X");
	public var controlButtonPane:JPanel = new JPanel();
	
	
	
	
	//	public function OFrame(owner:* = null, modal:Boolean = false, frameBackground:BitmapData = null, textBackground:BitmapData = null)
	public function OFrame(owner:* = null, modal:Boolean = false, frameBackground:BitmapAttacher = null, textBackground:BitmapAttacher = null)
	{
		
		super(owner,modal)
		
		this.setLayout(new EmptyLayout());
		
		this.setSizeWH(windowWidth,windowHeight);
		
		// add skin to frame and text.
		if (frameBackground && textBackground)
		{
			var frameDecorator:AssetBackground = new AssetBackground(frameBackground);
			this.setBackgroundDecorator(frameDecorator);
			var textDecorator:AssetBackground = new AssetBackground(textBackground);
			text.setBackgroundDecorator(textDecorator);
		}
		
		//begin layout
		//buttonBar
		buttonBar.appendAll(prevBtn,nextBtn);
		buttonBar.setSizeWH(windowWidth*3/4,buttonHeight);
		buttonBar.setLocationXY((windowWidth-buttonBar.width)/2,windowHeight-buttonHeight);
		
		//textPane
		textPane.setSizeWH(this.width*3/4, this.height-buttonHeight-titleHeight);
		textPane.setLocationXY((windowWidth-textPane.width)/2,titleHeight);
		text.setWordWrap(true);
		text.setText("");
		
		//title
		myTitle.setSizeWH(this.width, titleHeight);
		myTitle.setLocationXY(0,0);
		
		//end layout
		this.append(myTitle);
		//newly added 20130511.213817
		controlButtonPane.append(xbtn);
		controlButtonPane.setSizeWH(25*controlButtonPane.numChildren,25);
		controlButtonPane.setLocationXY(this.width-25*controlButtonPane.numChildren,0);
		
		this.append(controlButtonPane);
		this.append(textPane);
		this.append(buttonBar);
	}
	
	public function setTitle(string:String):void
	{
		myTitle.setText(string);
	}
}